Node data type conversion for service clients
You may have noticed that the Schema Editor
provided by BizTalk Server 2009 delivers a comprehensive list of data
types for schema nodes. In this table, I call out each schema type,
what it is, and what .NET type it converts to when consumed by the WCF svcutil.exe proxy generation tool.
BizTalk XSD Type
|
Description
|
.NET Type
|
---|
anyURI
|
Can be any absolute or relative Uniform Resource Identifier Reference
|
System.String
|
base64Binary
|
Holds Base64-encoded arbitrary binary data (e.g. PDF, JPEG)
|
System.Byte[]
|
boolean
|
Supports the mathematical concept of binary value logic (0/1 or true/false)
|
System.Boolean
|
byte
|
Holds an 8-bit value
|
System.SByte
|
date
|
Object with year, month, and day properties
|
System.DateTime
|
dateTime
|
Object with year, month, day, hour, minute, second, and timezone properties
|
System.DateTime
|
decimal
|
Contains a subset of real numbers with support for at a minimum of 18 decimal digits
|
System.Decimal
|
double
|
A double precision 64-bit floating point type
|
System.Double
|
duration
|
Represents a duration of time consisting of year, month, day, hour, minute and second
|
System.String
|
ENTITIES
|
Separated list of ENTITY references
|
System.String
|
ENTITY
|
Unparsed entity that may include non-XML content
|
System.String
|
float
|
A single precision 32-bit floating point type
|
System.Single
|
BizTalk XSD Type
|
Description
|
.NET Type
|
gDay
|
Equal to a day recurring each month
|
System.String
|
gMonth
|
Equal to a month recurring each year
|
System.String
|
gMonthDay
|
A calendar date (month + day) recurring each year
|
System.String
|
gYear
|
A period of a single year
|
System.String
|
gYearMonth
|
A particular calendar month in a specific year
|
System.String
|
hexBinary
|
Represents arbitrary hex-encoded binary data
|
System.Byte[]
|
ID
|
Definition of document-global unique identifiers
|
System.String
|
IDREF
|
A reference to a unique identifier (ID)
|
System.String
|
IDREFS
|
Separated list of IDREF references
|
System.String
|
int
|
A 32-bit signed integer
|
System.Int32
|
integer
|
A signed integer of arbitrary length
|
System.String
|
language
|
Set of language codes called out in RFC 3066 (e.g. en-US)
|
System.String
|
long
|
64-bit signed integer
|
System.Int64
|
Name
|
XML string with no whitespace
|
System.String
|
NCName
|
Name that conforms to namespace standard (e.g. no colons)
|
System.String
|
negativeInteger
|
Encompasses all strictly negative integers
|
System.String
|
NMTOKEN
|
Set of XML "name tokens" excluding spaces or commas
|
System.String
|
NMTOKENS
|
Separated list of NMTOKENS
|
System.String
|
nonNegativeInteger
|
Encompasses all positive integers (including zero)
|
System.String
|
nonPositiveInteger
|
Encompasses all negative integers (including 0)
|
System.String
|
normalizedString
|
Contains whitespace-replaced strings (meaning all carriage returns, tabs, etc have been replaced)
|
System.String
|
positiveInteger
|
Encompasses all strictly positive integers
|
System.String
|
QName
|
Qualified name as a combination of namespace name and part name
|
XmlQualifiedName
|
short
|
Set of 16-bit integers
|
System.Int16
|
BizTalk XSD Type
|
Description
|
.NET Type
|
string
|
String of any set of XML allowable characters, including whitespace
|
System.String
|
time
|
Instant of time recurring each day
|
System.DateTime
|
token
|
Set of strings with whitespace replacement of leading/trailing spaces,
carriage return, line feed, tab, and any instance of two or more
spaces. |
System.String
|
unsignedByte
|
8-bit unsigned value
|
System.Byte
|
unsignedInt
|
32-bit unsigned integer
|
System.UInt32
|
unsignedLong
|
64-bit unsigned integer
|
System.UInt64
|
unsignedShort
|
16-bit unsigned integer
|
System.UInt16
|
It's interesting to see how some types are handled. For maximum interoperability, stick with very common types like string and int. As you move into floating point numbers, consider using the decimal type instead of the float type so that you can get the maximum precision on your numbers and not fall prey to rounding errors.
One interesting data type to note, that I don't come across very often, is the ID/IDREF. ID/IDREF
is a concept left over from DTD where you can define relationships
between XML nodes. The ID value acts as a primary key (and must be
unique in the message) while the IDREF field points to the ID field.
In a schema, I have sections of dependent elements that are not
structured in a way to enforce the relationship. For instance, recall
that one version of my Enrollment schema has a repeating list of addresses in order to account for home, work, and alternate addresses. I may have a new element in this schema named PrimaryAddress
that references which of the included addresses we should treat as the
default one. Using basic XML data types, there is no way to enforce
that the PrimaryAddress node can
only contain a value that corresponds to the repeating list of
addresses. However, if I update my schema to apply ID/IDREF data types
to the corresponding address nodes and then validate the below XML
snippet in the BizTalk Schema Editor, I get the exception Reference to undeclared ID is 'Alternate'.
<ns0:Subject xmlns:ns0="http://Seroter.BizTalk.SOA.Chapter5/Import">
<ID>ID_0</ID>
<Name>
<First>First_0</First>
<Middle>Middle_0</Middle>
<Last>Last_0</Last>
</Name>
<DOB>DOB_0</DOB>
<Gender>Gender_0</Gender>
<PhysicianID>PhysicianID_0</PhysicianID>
<PrimaryAddress>Alternate</PrimaryAddress>
<Addresses>
<Type>Home</Type>
<Street>Street_0</Street>
<City>City_0</City>
<State>State_0</State>
<PostalCode>PostalCode_0</PostalCode>
<Country>Country_0</Country>
</Addresses>
<Addresses>
<Type>Work</Type>
<Street>Street_0</Street>
<City>City_0</City>
<State>State_0</State>
<PostalCode>PostalCode_0</PostalCode>
<Country>Country_0</Country>
</Addresses>
</ns0:Subject>
Hence, while it remains difficult-to-impossible to build strong relationship semantics into a schema, consider ID/IDREF if you need to enforce basic referential integrity in your service schema.